package com.example.cyberqueueandroid;

import java.util.ArrayList;

public class Utils {
	private static String PREFIX = "CQ_";

	public static String getQeuueFromCockie(String cockie) {
		String sub = cockie.substring(PREFIX.length());
		String[] splited = sub.split("=");
		if (splited[0].length() <= 10) {
			return null;
		}
		return splited[0];
	}

	public static String getUserFromCockie(String cockie) {
		String sub = cockie.substring(PREFIX.length());
		String[] splited = sub.split("=");
		if (splited[1].length() != 5) {
			return null;
		}
		return splited[1];
	}

	public static ArrayList<String> splitQueuesCockie(String cockie) {
		if (cockie == null) {
			return new ArrayList<String>();
		}
		ArrayList<String> cyberCookies = new ArrayList<String>();
		String[] cookies = cockie.split(";");
		for (String c : cookies) {
			if (c.trim().startsWith(PREFIX)) {
				cyberCookies.add(c.trim());
			}
		}
		return cyberCookies;
	}
}
